package utils;


import org.springframework.util.StringUtils;

/**
 * StringUtils 工具类
 */
public final class CommonStringUtils extends StringUtils {

    private final static String NUMBER_REGEX = "[0-9]+";

    public static boolean isBlank(Object obj) {
        return obj == null || isBlank(obj.toString());
    }

    public static boolean isNotBlank(Object obj) {
        return !isBlank(obj);
    }

    public static String objToStr(Object o) {
        String str = o == null ? "" : o.toString();
        return str.trim();
    }

    public static boolean isEmpty(CharSequence cs) {
        return cs == null || cs.length() == 0;
    }

    /**
     * 判断字符串中只能有字母 数字 中文
     * @param str
     * @return
     */
    public static boolean isLetterDigitOrChinese(String str) {
        String regex = "^[a-z0-9A-Z\u4e00-\u9fa5]+$";
        return str.matches(regex);
    }

    /**
     * 判断字符串是否是纯数字组成
     * @param str
     * @return
     */
    public static boolean isNumber(String str) {
        return str.matches(NUMBER_REGEX);
    }

    /**
     * 替换字符串中的{*}占位符
     *
     * @param strContainsPlaceHolder
     * @param parms
     * @return
     */
    public static String format(String strContainsPlaceHolder, Object... parms) {
        String regex = "\\{.*\\}";
        String newStrVal = strContainsPlaceHolder.replaceAll(regex, String.valueOf(parms[0]));
        return newStrVal;
    }

}
